package com.igeekhome.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.IWorkQualityStatisticsService;
import com.igeekhome.biz.IWorkloadStatisticsService;
import com.igeekhome.pojo.WorkQualityStatistics;
import com.igeekhome.pojo.WorkloadStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 工作量统计 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/workloadStatistics")

public class WorkloadStatisticsController {

    @Autowired
    private IWorkloadStatisticsService iWorkloadStatisticsService;

    @RequestMapping("/workload")
    public String Workload(HttpSession session, Model model, @RequestParam("value")String value, @RequestParam("current")Integer current, @RequestParam("size")Integer size){
        IPage<WorkloadStatistics> page =new Page<>(current,size);

        QueryWrapper<WorkloadStatistics> qw=new QueryWrapper<>();
        qw.like("nickname",value).or().like("id", value).or().like("totalmessagecount", value).or().like("totalsessioncount", value).or().like("totaleffectivesessioncount",value).or().like("totalendsessioncount",value).or().like("totalsessiontime",value);
        IPage<WorkloadStatistics> page1=iWorkloadStatisticsService.page(page,qw);
        List<WorkloadStatistics> list = page1.getRecords();

        session.setAttribute("workloadCount",this.iWorkloadStatisticsService.count());

        long pagesCount=page1.getPages();
        model.addAttribute("list",list);
        model.addAttribute("pagesCount",pagesCount);

        return "workloadbiao";

    }
//    @RequestMapping("/search")
//    public String search(Model model, String value){
//        QueryWrapper<WorkloadStatistics> qw=new QueryWrapper<>();
////        qw.like("realname",value);
//        qw.like("nickname",value).or().like("id", value).or().like("totalmessagecount", value).or().like("totalsessioncount", value).or().like("totaleffectivesessioncount",value).or().like("totalendsessioncount",value).or().like("totalsessiontime",value);
//        List<WorkloadStatistics> list=iWorkloadStatisticsService.list(qw);
//        model.addAttribute("list",list);
//
//        return "workloadbiao";
//    }

}

